<?php
$appLinks = Blyn::app()->getAppUI()->getLinks();
$workingMenus = $appLinks['workingSpaceLinks'];
$followingMenus = $appLinks['followingSpaceLinks'];
$adminSpaceLinks = $appLinks['adminSpaceLinks'];

$workingSpacesStr = Yii::t('site','Working Spaces');
$followingSpacesStr = Yii::t('site','Following Spaces');
$mostVisitsSpacesStr = Yii::t('site','Most Visits Spaces');

foreach ($adminSpaceLinks as $spaceId => $value) {
    $workingMenus[$spaceId] = $value;
}
//$currentApp = Blyn::app()->getActiveApp()->getUIManager();
$mySpacesAjaxObj = Blyn::app()->getUIManager()->getCurrentScreen();
//$mySpacesAjaxObj = $uiObj;


//$workingSpacesLink = $currentScreen->getAjaxLink("Working Spaces", array('ajaxContainer' => "show_mySpaces_content", 'ajaxView' => 'mySpaces'));
$workingSpacesLink = $mySpacesAjaxObj->getAjaxLink($workingSpacesStr, array('ajaxContainer' => "show_mySpaces_content", 'ajaxView' => 'mySpaces'));
//$followingSpacesLink = $currentScreen->getAjaxLink('Following Spaces', array('ajaxContainer' => "show_mySpaces_content", 'ajaxView' => 'mySpaces'));
$followingSpacesLink = $mySpacesAjaxObj->getAjaxLink($followingSpacesStr, array('ajaxContainer' => "show_mySpaces_content", 'ajaxView' => 'mySpaces'));
//$visitSpacesLink = $currentScreen->getAjaxLink('Most Visits Spaces', array('ajaxContainer' => "show_mySpaces_content", 'ajaxView' => 'mySpaces'));
$visitSpacesLink = $mySpacesAjaxObj->getAjaxLink($mostVisitsSpacesStr, array('ajaxContainer' => "show_mySpaces_content", 'ajaxView' => 'mySpaces'));

$activeLink = $mostVisitsSpacesStr;



//if ($currentScreen->isAjaxLinkClicked('Most Visits Spaces', 'mySpaces')) {
if ($mySpacesAjaxObj->isAjaxLinkClicked($mostVisitsSpacesStr, 'mySpaces')) {
    $activeLink = $mostVisitsSpacesStr;
}

//if ($currentScreen->isAjaxLinkClicked('Working Spaces', 'mySpaces')) {
if ($mySpacesAjaxObj->isAjaxLinkClicked($workingSpacesStr, 'mySpaces')) {
    $activeLink = $workingSpacesStr;
}

//if ($currentScreen->isAjaxLinkClicked('Following Spaces', 'mySpaces')) {
if ($mySpacesAjaxObj->isAjaxLinkClicked($followingSpacesStr, 'mySpaces')) {
    $activeLink = $followingSpacesStr;
}
?>
<div class="row-fluid" style="margin-bottom: 20px;margin-top: -15px">
    <div class="span5"></div>    
    <div class="span7">
        <div class="btn-group">
            <a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
                <?php echo $activeLink; ?>
                <span class="caret"></span>
            </a>
            <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu">
                <li><?php echo $visitSpacesLink; ?></li>  
                <li><?php echo $workingSpacesLink; ?></li>                 
                <li><?php echo $followingSpacesLink; ?></li>              
            </ul>
        </div>
    </div>
</div>
<?php
$workingSpaceStr = Yii::t('site','Working Space');
$noDescriptionSoFarStr = Yii::t('site','No description so far');
if ($activeLink == $mostVisitsSpacesStr || $activeLink == $workingSpacesStr) {
    foreach ($workingMenus as $link) {
        ?>
        <div class="well" style="padding: 10px">
            <div class="row-fluid">
                <div class="span4"><strong> <?php echo $link['ajaxUrl']; ?></strong></div>
                <div class="span3"></div>
                <div class="span5"><?php echo $workingSpaceStr; ?></div>
            </div>
            <div class="row-fluid">   
                <div class="span11"><?php echo $noDescriptionSoFarStr; ?>...</div>
                <div class="span1"></div>
            </div>
        </div>
        <?php
    }
}
?>
<?php
$followingSpaceStr = Yii::t('site','Following Space');
if ($activeLink == $mostVisitsSpacesStr || $activeLink == $followingSpacesStr) {
    foreach ($followingMenus as $link) {
        ?>
        <div class="well" style="padding: 10px">
            <div class="row-fluid">
                <div class="span4"><strong> <?php echo $link['ajaxUrl']; ?></strong></div>
                <div class="span3"></div>
                <div class="span5"><?php echo $followingSpaceStr; ?></div>
            </div>
            <div class="row-fluid">   
                <div class="span11"><?php echo $noDescriptionSoFarStr; ?>...</div>
                <div class="span1"></div>
            </div>
        </div>
        <?php
    }
}
?>
